﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EEPClientDBSocket
{
    public partial class frmFields : Form
    {
        public frmFields()
        {
            InitializeComponent();
        }

        List<String> fields = new List<string>();
        String[] selected = null;
        public frmFields(List<String> f, String[] s)
        {
            fields = f;
            selected = s;
            InitializeComponent();
        }

        private void frmFields_Load(object sender, EventArgs e)
        {
            foreach (String str in fields)
            {
                bool flag = false;
                foreach (String s in selected)
                    if (s == str) flag = true;
                if (!flag && str != "")
                    this.lbUnselected.Items.Add(str);
            }

            foreach (String str in selected)
                if (str != "")
                    this.lbSelected.Items.Add(str);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public String values;
        private void btnOK_Click(object sender, EventArgs e)
        {
            foreach (String str in this.lbSelected.Items)
                values += str + ";";
            values = values.Remove(values.LastIndexOf(";"));
            this.Close();
        }

        private void btnMoveAll_Click(object sender, EventArgs e)
        {
            foreach (String str in this.lbUnselected.Items)
                if (str != "")
                    lbSelected.Items.Add(str);
            this.lbUnselected.Items.Clear();
        }

        private void btnBackAll_Click(object sender, EventArgs e)
        {
            foreach (String str in this.lbSelected.Items)
                if (str != "")
                    lbUnselected.Items.Add(str);
            this.lbSelected.Items.Clear();
        }

        private void btnMove_Click(object sender, EventArgs e)
        {
            if (this.lbUnselected.SelectedItems.Count > 0)
            {
                this.lbSelected.Items.Add(this.lbUnselected.SelectedItem.ToString());
                this.lbUnselected.Items.Remove(this.lbUnselected.SelectedItem.ToString());
            }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            if (this.lbSelected.SelectedItems.Count > 0)
            {
                this.lbUnselected.Items.Add(this.lbSelected.SelectedItem.ToString());
                this.lbSelected.Items.Remove(this.lbSelected.SelectedItem.ToString());
            }
        }
    }
}